
include version

# cross compile for windows / wine by default
#CC= i586-mingw32msvc-gcc
#CXX= i586-mingw32msvc-g++
#AR= i586-mingw32msvc-ar
#RANLIB= i586-mingw32msvc-ranlib

RANLIB=ranlib

CPPFLAGS= -pg -msse2 -mfpmath=sse
CXXFLAGS= -I./squish-1.10 -I./lua-5.1.4/include

BIN= mapc
PACKAGE= mapcwin

SRC = MapConv.cpp Bitmap.cpp bmp_io.cpp TileHandler.cpp FileHandler.cpp \
	HpiHandler.cpp float3.cpp MemPool.cpp FeatureCreator.cpp

OBJ = $(SRC:%.cpp=%.o)

all: squish lua $(BIN)

$(BIN): $(OBJ)
	$(CXX) $(CPPFLAGS) -I. $(CXXFLAGS) -o $(BIN) $(OBJ) squish-1.10/libsquish.a lua-5.1.4/src/liblua.a

squish:
	cd squish-1.10 && $(MAKE) all CXX=$(CXX) AR=$(AR) RANLIB=$(RANLIB)

lua:
	cd lua-5.1.4 && $(MAKE) generic \
	CC=$(CC) CXX=$(CXX) AR="$(AR) rcu" RANLIB=$(RANLIB)

%.o : %.cpp
	$(CXX) $(CPPFLAGS) -I. $(CXXFLAGS) -o$@ -c $<

dist: 
	mkdir $(PACKAGE)-$(VERSION)
	cp $(BIN) $(PACKAGE)-$(VERSION)
	cp mapconv.lua $(PACKAGE)-$(VERSION)
	cp -a chasmofchaos1 $(PACKAGE)-$(VERSION)
	zip -r $(PACKAGE)-$(VERSION).zip $(PACKAGE)-$(VERSION)

distclean: clean
	rm -rf $(PACKAGE)-$(VERSION)
	rm -f $(PACKAGE)-$(VERSION).zip

mingw:
	$(MAKE) all BIN=mapc.exe CXX=i586-mingw32msvc-g++ CC=i586-mingw32msvc-gcc \
	AR=i586-mingw32msvc-ar RANLIB=i586-mingw32msvc-ranlib PACKAGE=mapclinux

linux:
	$(MAKE) all BIN=mapc CXX=g++ CC=gcc AR=ar RANLIB=ranlib PACKAGE=mapclinux

clean:
	rm -f $(BIN) $(OBJ) mapc mapc.exe
	cd lua-5.1.4 && make clean
	cd squish-1.10 && make clean

#.PHONY: dist-mingw dist-linux

